package com.test5.liang.service;


import com.test5.liang.dao.UserMapper;
import com.test5.liang.dao.registerLogMapper;
import com.test5.liang.pojo.registerLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.List;

@Service
public class registerLogService {

    @Autowired
    registerLogMapper registerLogMapper;


    public int insertRegisterLog(registerLog registerLog){
        return registerLogMapper.insertRegisterLog(registerLog);
    }

    public registerLog selectTodayRegisterLogbyUserId(Long userId){

        return registerLogMapper.selectTodayRegisterLogbyUserId(userId);
    }

    public int updateRegisterLog(registerLog registerLog){
        if (registerLog.getUserTemperature()>36&&registerLog.getUserTemperature()<=37){
            registerLog.setHealthyStatus(1);
        }else {
            registerLog.setHealthyStatus(0);
        }
        registerLog.setStatus(1);
        return registerLogMapper.updateRegisterLog(registerLog);
    }

    public List<registerLog> selectAllRegisterLogByUserId(Long userId){
        //转化一下时间格式

        List<registerLog> registerLogs = registerLogMapper.selectAllRegisterLogByUserId(userId);
        for (registerLog registerLog : registerLogs) {
            String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(registerLog.getCreateTime());
            registerLog.setFormatTime(format);
        }
        return registerLogs;
    }

    public List<registerLog> selectAllRegisterLog(){
        List<registerLog> registerLogs = registerLogMapper.selectAllRegisterLog();
        return registerLogs;
    }

}
